package com.seuic.hnjiningposapp.hnapps.ui.view.dialog;

import android.content.Context;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lxj.xpopup.core.BasePopupView;
import com.seuic.hnjiningposapp.R;
import com.seuic.hnjiningposapp.hnapps.bean.UserAccBean;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 选择需要挂失的子账户
 */
public class SellossOfPp extends BasePopupView {
    Unbinder bind;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    List<UserAccBean> userAccBeans;
    Context mContext;
    SellCallBack mSellCallBack;

    public SellossOfPp(@NonNull Context context, SellCallBack sellCallBack) {
        super(context);
        mContext = context;
        mSellCallBack = sellCallBack;

    }

    public void setUserAccBeans(List<UserAccBean> userAccBeans) {
        this.userAccBeans = userAccBeans;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        bind = ButterKnife.bind(this);

        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        Adapter adapter = new Adapter(R.layout.sellossofpp_item_layout, null);
        recyclerView.setAdapter(adapter);

        recyclerView.addItemDecoration(new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL));


        adapter.setNewData(userAccBeans);

    }

    @Override
    protected int getPopupLayoutId() {
        return R.layout.sellossof_pp;
    }


    private class Adapter extends BaseQuickAdapter<UserAccBean, BaseViewHolder> {
        public Adapter(int layoutResId, @Nullable List<UserAccBean> data) {
            super(layoutResId, data);
        }

        @Override
        protected void convert(@NotNull BaseViewHolder baseViewHolder, UserAccBean userAccBean) {
            TextView num, accnum, username, classify, type;
            Button tbnt;
            num = baseViewHolder.findView(R.id.item_numtv);//序号
            accnum = baseViewHolder.findView(R.id.item_accnum);//账户
            username = baseViewHolder.findView(R.id.item_username);//姓名
            classify = baseViewHolder.findView(R.id.item_classify);//分类
            type = baseViewHolder.findView(R.id.item_type);//状态
            tbnt = baseViewHolder.findView(R.id.t_btn);

            num.setText("序号："+String.valueOf(baseViewHolder.getPosition() + 1));
            accnum.setText(userAccBean.getAcctNo().substring(0, userAccBean.getAcctNo().length() - 5) + "****" + userAccBean.getAcctNo().substring(userAccBean.getAcctNo().length() - 1));
            username.setText("*" + userAccBean.getAcctName().substring(1));
            if (userAccBean.getAcctClass().equals("01")) {
                classify.setText("一类户");
            } else if (userAccBean.getAcctClass().equals("02")) {
                classify.setText("二类户");
            } else if (userAccBean.getAcctClass().equals("03")) {
                classify.setText("三类户");
            }

            if (userAccBean.getAcctStatus().equals("0")){
                type.setText("待领");
            }else if (userAccBean.getAcctStatus().equals("1")){
                type.setText("待改密");
            }else if (userAccBean.getAcctStatus().equals("2")) {
                type.setText("正常");
            }else if (userAccBean.getAcctStatus().equals("3")) {
                type.setText("销户");
            }else if (userAccBean.getAcctStatus().equals("4")) {
                type.setText("没收");
            }else if (userAccBean.getAcctStatus().equals("5")) {
                type.setText("冻结");
            }else if (userAccBean.getAcctStatus().equals("6")) {
                type.setText("不正常");
            }


            tbnt.setOnClickListener(v -> {
                mSellCallBack.seLLCallData(userAccBean);
            });

        }
    }

    public interface SellCallBack {
        void seLLCallData(UserAccBean userAccBean);
    }


    @Override
    protected void onDismiss() {
        super.onDismiss();
        //注解解绑
        if (bind != null && bind != Unbinder.EMPTY) {
            bind.unbind();
        }
        this.bind = null;
    }

}
